home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / networking / pgpuam / sources / tpgpexception.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.1 KB  |  123 lines

  1. //------------------------------------------------------------------------------------
  2. //
  3. //    TPGPException  - PGP Exception Class Object
  4. // 
  5. // Apple Macintosh Developer Technical Support
  6. // Written by:  Vinnie Moscaritolo
  7. //
  8. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  9. //
  10. // You may incorporate this sample code into your applications without
  11. // restriction, though the sample code has been provided "AS IS" and the
  12. // responsibility for its operation is 100% yours.  However, what you are
  13. // not permitted to do is to redistribute the source as "DSC Sample Code"
  14. // after having made changes. If you're going to re-distribute the source,
  15. // we require that you make it clear in the source that the code was
  16. // descended from Apple Sample Code, but that you've made changes.
  17. // 
  18.  
  19.  
  20. #pragma once 
  21.  
  22. #include "pgpErrors.h"
  23.  
  24.  
  25. // ______________________________________________________________________________
  26. // EXCEPTION CLASSES
  27.  
  28. class TPGPException 
  29. {
  30. public:
  31.     TPGPException(const PGPError theError) :
  32.                     fMessage("NO MESSAGE SPECIFIED"), 
  33.                     fError(theError), 
  34.                     fFileName("NO FILE SPECIFIED"), 
  35.                     fLineNumber(0L) 
  36.                     {};
  37.  
  38.     TPGPException(const char *theMessage, const PGPError theError) :
  39.                     fMessage(theMessage), 
  40.                     fError(theError), 
  41.                     fFileName("NO FILE SPECIFIED"), 
  42.                     fLineNumber(0L) 
  43.                     {};
  44.                     
  45.     TPGPException(const char *theMessage, const PGPError theError, const char *theFileName, const long theLineNumber) :
  46.                     fMessage(theMessage), 
  47.                     fError(theError), 
  48.                     fFileName(theFileName), 
  49.                     fLineNumber(theLineNumber) 
  50.                     {};
  51.                     
  52.     const char*     GetExceptionMessage(void)     { return fMessage;};
  53.     const PGPError    GetExceptionErr(void)        { return fError;};
  54.     const char*        GetExceptionFile(void)        { return fFileName;};
  55.     const long        GetExceptionLine(void)        { return fLineNumber;};
  56.     
  57. protected:
  58.     const PGPError     fError;
  59.     const char*     fMessage;
  60.     const char*     fFileName;
  61.     const long        fLineNumber;
  62. };
  63.  
  64.  
  65. //------------------------------------------------------------------------------------
  66. #pragma mark Useful Macros
  67. //------------------------------------------------------------------------------------
  68.  
  69.  
  70. #define ThrowPGPIfNil( _val_ )                                        \
  71.         if ( (_val_) == nil )                                        \
  72.             throw TPGPException( "UNEXPECTED NIL RETURNED" ,0 , __FILE__, __LINE__)     
  73.  
  74. #define ThrowPGPIfNotNil( _val_ )                                                \
  75.         if ( (_val_) != nil )                                                    \
  76.             throw TPGPException( "EXPECTED NIL" ,0 , __FILE__, __LINE__) 
  77.  
  78. #define ThrowPGPIfTrue( _val_ )                                        \
  79.         if ( (_val_) )                                        \
  80.             throw TPGPException( "NO MESSAGE SPECIFIED" ,0 , __FILE__, __LINE__)     
  81.  
  82. #define ThrowPGPIfFalse( _val_ )                                                \
  83.         if ( !(_val_) )                                                    \
  84.             throw TPGPException( "NO MESSAGE SPECIFIED" ,0 , __FILE__, __LINE__) 
  85.  
  86. #define ThrowPGPErrIfTrue( _val_, _err_  )                                        \
  87.         if ( (_val_) )                                        \
  88.             throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)     
  89.  
  90. #define ThrowPGPErrIfFalse( _val_, _err_  )                                        \
  91.         if ( !(_val_) )                                        \
  92.             throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)     
  93.  
  94.  #define ThrowPGPErrIfNotNil( _val_, _err_  )                                        \
  95.         if ( (_val_) != nil )                                                    \
  96.             throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)     
  97.  
  98. #define ThrowPGPErrIfNil( _val_, _err_  )                                        \
  99.         if ( (_val_) == nil )                                        \
  100.             throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)     
  101.  
  102. #define ThrowIfPGPErr(_err_)                                        \
  103.         { PGPError _temp_ = (_err_);    \
  104.         if ( _temp_ != kPGPError_NoErr)                                            \
  105.             throw TPGPException( "NO MESSAGE SPECIFIED",  _temp_, __FILE__, __LINE__); }
  106.  
  107. #define ThrowPGPErr(_err_)                                                \
  108.             throw TPGPException( "NO MESSAGE SPECIFIED", (_err_), __FILE__, __LINE__)     
  109.  
  110. #define ThrowPGPMsgIfErr(_err_, _Msg_)                                        \
  111.         if ((_err_) != kPGPError_NoErr)                                            \
  112.             throw TPGPException( (_Msg_), (_err_), __FILE__, __LINE__)     
  113.  
  114.  
  115. #define ThrowPGPErr(_err_)                                                \
  116.             throw TPGPException( "NO MESSAGE SPECIFIED", (_err_), __FILE__, __LINE__)     
  117.  
  118. #define ThrowMsgIfPGPErr(_err_, _Msg_)                                        \
  119.         { PGPError _temp_ = (_err_);    \
  120.         if ( _temp_ != kPGPError_NoErr)                                            \
  121.             throw TPGPException( (_Msg_), _temp_, __FILE__, __LINE__); }
  122.  
  123.